package util;

import java.security.MessageDigest;


public class EncryptUtil {
	//加密盐值
	private static final String salt = "$%^DFGHRT464GVHJ";
	//md5加密方法
	public static String getMD5(String str){
		String string = salt + str;
		return md5(string);
	}
	//md5加密
	private static String md5(String string){
		char md5String[] ={'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  
                'A', 'B', 'C', 'D', 'E', 'F'};
		try{
			byte[] btInput = string.getBytes();
			MessageDigest mdInt = MessageDigest.getInstance("MD5");
			mdInt.update(btInput);
			byte[] md = mdInt.digest();
			int j = md.length;
			char str[] = new char[j * 2];
			int k = 0;
			for (int i = 0; i < j; i++) {
				byte byte0 = md[i];
				str[k++] = md5String[byte0 >>> 4 & 0xf];
				str[k++] = md5String[byte0 & 0xf];
			}
			//返回加密后的字符串
			return new String(str);
		}catch(Exception e){
			return null;
		}
	}
	//测试
//	public static void main(String[] args) {
//		EncryptUtil encryptUtil= new EncryptUtil();
//		System.out.println(encryptUtil.getMD5("wefnwfij"));
//	}
}
